/**
 * amis v2.4.0
 * Copyright 2018-2022 baidu
 */

import { __extends, __decorate } from 'tslib';
import React from 'react';
import { filter, Renderer } from 'amis-core';
import { withBadge } from 'amis-ui';
import { getIcon } from 'amis-ui/lib/components/icons';
import { isObject } from 'lodash';

var Icon = /** @class */ (function (_super) {
    __extends(Icon, _super);
    function Icon() {
        return _super !== null && _super.apply(this, arguments) || this;
    }
    Icon.prototype.render = function () {
        var _a = this.props, vendor = _a.vendor, cx = _a.classnames, className = _a.className, data = _a.data;
        var icon = this.props.icon;
        icon = filter(icon, data);
        if (typeof icon !== 'string') {
            if (isObject(icon) &&
                typeof icon.id === 'string' &&
                icon.id.startsWith('svg-')) {
                return (React.createElement("svg", { className: cx('icon', className) },
                    React.createElement("use", { xlinkHref: "#".concat(icon.id.replace(/^svg-/, '')) })));
            }
            return;
        }
        var CustomIcon = getIcon(icon);
        if (CustomIcon) {
            return React.createElement(CustomIcon, { className: cx(className, "icon-".concat(icon)) });
        }
        var isURLIcon = (icon === null || icon === void 0 ? void 0 : icon.indexOf('.')) !== -1;
        var iconPrefix = '';
        if (vendor === 'iconfont') {
            iconPrefix = "iconfont icon-".concat(icon);
        }
        else if (vendor === 'fa') {
            //默认是fontawesome v4，兼容之前配置
            iconPrefix = "".concat(vendor, " ").concat(vendor, "-").concat(icon);
        }
        else {
            // 如果vendor为空，则不设置前缀,这样可以支持fontawesome v5、fontawesome v6或者其他框架
            iconPrefix = "".concat(icon);
        }
        return isURLIcon ? (React.createElement("img", { className: cx('Icon'), src: icon })) : (React.createElement("i", { className: cx(iconPrefix, className) }));
    };
    Icon.defaultProps = {
        icon: '',
        vendor: 'fa'
    };
    return Icon;
}(React.Component));
/** @class */ ((function (_super) {
    __extends(IconRenderer, _super);
    function IconRenderer() {
        return _super !== null && _super.apply(this, arguments) || this;
    }
    IconRenderer = __decorate([
        Renderer({
            type: 'icon'
        })
        // @ts-ignore 类型没搞定
        ,
        withBadge
    ], IconRenderer);
    return IconRenderer;
})(Icon));

export { Icon };
